Merged [21207]: Sparkle+ [103], which allows the delegate to pass values to be sent...
[adiumx.git] / Plugins / Contact Profile / AIContactProfilePane.m
blobe77871672be55f15456bab70919b8ff01f67b1fd
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "AIContactProfilePane.h"
18 #import <Adium/AIContentControllerProtocol.h>
19 #import <AIUtilities/AIAttributedStringAdditions.h>
20 #import <AIUtilities/AILinkTextView.h>
21 #import <AIUtilities/AITextAttributes.h>
22 #import <Adium/AIListContact.h>
23 #import <Adium/AIListObject.h>
24 #import "AILocalizationTextField.h"
26 /*!
27  * @class AIContactProfilePane
28  * @brief Pane for contact info and profile
29  *
30  * Man, this is ugly.
31  */
32 @implementation AIContactProfilePane
34 /*!
35  * @brief Category
36  */
37 - (AIContactInfoCategory)contactInfoCategory{
38     return AIInfo_Profile;
40 /*!
41  * @brief Nib name
42  */
43 - (NSString *)nibName{
44     return @"ContactProfilePane";
47 //Configure the preference view
48 - (void)viewDidLoad
50         viewIsOpen = YES;
51         
52         [label_status setLocalizedString:[AILocalizedString(@"Status",nil) stringByAppendingString:AILocalizedString(@":", nil)]];
53         [label_profileIfAvailable setLocalizedString:AILocalizedString(@"Profile (if available):",nil)];
55     [[adium contactController] registerListObjectObserver:self];
58 //Preference view is closing
59 - (void)viewWillClose
61         viewIsOpen = NO;
62     [[adium contactController] unregisterListObjectObserver:self];
63         [listObject release]; listObject = nil;
66 //Configure the pane for a list object
67 - (void)configureForListObject:(AIListObject *)inObject
69         //New list object
70         if (inObject != listObject) {
71                 [listObject release];
72                 listObject = [inObject retain];
73         }
74         
75         //Display what we have now
76         [self updatePane];
77         
78         //Refresh the window's content (Contacts only)
79         if ([listObject isKindOfClass:[AIListContact class]]) {
80                 [[adium contactController] updateListContactStatus:(AIListContact *)listObject];
81         }
84 //Refresh if changes are made to the object we're displaying
85 - (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
87     if (inObject == listObject) {
88         [self updatePane];
89     }
90     return nil;
93 //Update our pane to reflect our contact
94 - (void)updatePane
95 {       
96         //Text Profile
97         [[adium contentController] filterAttributedString:([listObject isKindOfClass:[AIListContact class]] ?
98                                                                                                            [(AIListContact *)listObject profile] :
99                                                                                                            nil)
100                                                                           usingFilterType:AIFilterDisplay
101                                                                                         direction:AIFilterIncoming
102                                                                                 filterContext:listObject
103                                                                           notifyingTarget:self
104                                                                                          selector:@selector(gotFilteredProfile:context:)
105                                                                                           context:listObject];
106         //Away & Status
107         [[adium contentController] filterAttributedString:[listObject statusMessage]
108                                                                           usingFilterType:AIFilterDisplay
109                                                                                         direction:AIFilterIncoming
110                                                                                 filterContext:listObject
111                                                                           notifyingTarget:self
112                                                                                          selector:@selector(gotFilteredStatus:context:)
113                                                                                           context:listObject];
116 - (void)gotFilteredProfile:(NSAttributedString *)infoString context:(AIListObject *)object
118         if (viewIsOpen)
119                 [self setAttributedString:infoString intoTextView:textView_profile];
122 - (void)gotFilteredStatus:(NSAttributedString *)infoString context:(AIListObject *)object
124         if (viewIsOpen)
125                 [self setAttributedString:infoString intoTextView:textView_status];
129 - (void)setAttributedString:(NSAttributedString *)infoString intoTextView:(NSTextView *)textView
131         NSColor         *backgroundColor = nil;
133         if (infoString && [infoString length]) {
134                 [[textView textStorage] setAttributedString:infoString];        
135                 backgroundColor = [infoString attribute:AIBodyColorAttributeName
136                                                                                 atIndex:0 
137                                                   longestEffectiveRange:nil 
138                                                                                 inRange:NSMakeRange(0,[infoString length])];
139         } else {
140                 [[textView textStorage] setAttributedString:[NSAttributedString stringWithString:@""]]; 
141         }
142         [textView setBackgroundColor:(backgroundColor ? backgroundColor : [NSColor whiteColor])];
143     [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidChangeNotification object:textView];
147 @end